#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include "topbar.h"
#include "twitlist.h"
#include "settings.h"
#include "QTwitLib.h"
#include "about.h"
#include "statusbar.h"
#include "queue.h"
#include <QFile>
#include <QString>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QButtonGroup>
#include <QTimer>

#define DEFAULT_UPD_BY_CLICK_TIME   10000
#define DEFAULT_TWITTERUP_STATUS_CHECK_TIME  60000

#define DEFAULT_TRAY_ICON   ":/images/qwitik16.png"
#define DEFAULT_ACT_EXIT_ICON   ":/images/exit.png"
#define DEFAULT_ACT_ABOUTQT_ICON    ":/images/aboutQt.png"
#define DEFAULT_ACT_ABOUT_ICON  ":/images/about.png"
#define DEFAULT_ACT_CONF_ICON   ":/images/configure.png"
#define DEFAULT_ACT_SHOW_ICON   ":/images/show.png"
#define DEFAULT_ACT_HIDE_ICON   ":/images/hide.png"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    virtual ~MainWindow();

    enum STATE {
        LOGIN,
        RELOGIN,
        RUNNING
    };

    void setSkin();
    void init();

private:
    TopBar *topBar;
    QString skin;
    QTimer *start_timer;

    void initLogin();

    MainWindow::STATE state;

    //Tabs
    QButtonGroup *twitTabsGrp;
    enum TwitTabsButton { Friends, Public, User, Mentions, Nothing = 100};
    TwitTabsButton privTabState;

    //Timers
    QTimer *updateTimer;
    QTimer *updateByClickTimer;
    QTimer *twitterStatusTimer;

    TwitList *twitList;

    StatusBar *statusBar;

    Queue *twit_queue;

//SysTray
    void createSysTray();
    void createTrayMenu();
    void createMenuActions();
    QSystemTrayIcon *sysTrayIcon;
    QMenu *trayMenu;
        QAction *actExit;
        QAction *actAboutQt;
        QAction *actAbout;
        QAction *actShowHide;
        QAction *actConfigure;
        QAction *actLogging;
    void sysTrayShowHideIcon(bool isShow = true);

//Settings
    Settings *settingsDialog;

//TwitApi
    QTwitLib *twitLib;

//About
    About *about;

    QToolBar *twitTabs;
    QToolBar *topToolBar;



private slots:
    void OnResponseReceived(Returnables::Response *);
    void OnStatusReceived(SERVER::RESP resp);
    void OnError(QHttp::Error error);
    void initSettings();
    void ReLogin();

    void startingUp();

    void sendStatus(QString status);

    void runCommand(Returnables::RequestId comm, QList<QVariant> param);

    //Tabs
    void twitTabsClicked(int i);
    void updateTwitTabs(int i);
    void allowUpdateByClick();
    void updateTimeOut();

    //Settings
    void updateToolBarsState();

    //Twitter status
    void checkTwitterStatus();


    void sysTrayActivated(QSystemTrayIcon::ActivationReason reason);
    void sysTrayShowHide();

    void replyClicked(QString screenName);
    void favoritClicked(quint64 statusId, bool favorited);
    void trashClicked(quint64 statusId);

protected:
    void hideEvent(QHideEvent *event);
    void showEvent(QShowEvent *event);
    void resizeEvent(QResizeEvent *event);
    void moveEvent(QMoveEvent *event);
};

#endif // MAINWINDOW_H
